package com.hy.mydesktop;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.ejb.Ejb3Configuration;

import com.hy.mydesktop.shared.persistence.domain.User;


public class T {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		EntityManagerFactory entityManagerFactory = null;
		//Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
		
		//System.err.println(Persistence.createEntityManagerFactory("mydesktop"));
		entityManagerFactory = Persistence.createEntityManagerFactory("mydesktop");
		//entityManagerFactory = ejb3Configuration.buildEntityManagerFactory();	

		System.err.println(entityManagerFactory);
		EntityManager entityManager = entityManagerFactory.createEntityManager();
		entityManager.getTransaction().begin();
		entityManager.persist(new User());
		entityManager.getTransaction().commit();
		entityManager.close();
				
		entityManagerFactory.close();
		
		/* 3.6版本中已经废弃
		 * Deprecated. All functionality has been moved to Configuration 
		 * 
		 * SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
		 * */
		/*SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		

		Session session = sessionFactory.getCurrentSession();
		//session.beginTransaction();
		//session.save(s);
		//session.getTransaction().commit();
		session.close();
		sessionFactory.close();*/
	}

}
